package com.ellricky.tv.adapter

import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.adapter.SmartViewHolder
import com.ellricky.baselib.entity.new.WareLearn
import com.ellricky.tv.R

class TvCourseAdapter : BaseRecyclerAdapter<WareLearn>(R.layout.tv_item_course) {

    private val mTempColor = arrayOf("#C0E4E8", "#A2D7DE", "#9ED8F0", "#8BC1EA", "#83A2D3", "#688AAC", "#018699",
            "#02A3B1", "#2983A5", "#59B8C8", "#0095C5", "#4C6BA9", "#BDBBE2", "#887AAA", "#4C5AB0")

    override fun onBindViewHolder(holder: SmartViewHolder?, entity: WareLearn?, position: Int) {
        holder?.text(R.id.tvName, entity?.ware_name)
        holder?.text(R.id.tvAge, entity?.ware_sort)
        val shapeDrawable = holder?.itemView?.background
                as GradientDrawable
        shapeDrawable.setColor(Color.parseColor(getBackgroundColor()))
    }

    private fun getBackgroundColor(): String {
        return mTempColor[(Math.random() * 10 + 4).toInt()]
    }
}